;
(function (window, angular) {
    'use strict';
    angular.module("Service.UserContext", [])
        .service("UserContextService", ["$q", "ybHttp", "ybConfig", "$window", "$filter", "EventBus", "Upload", "ybWidget", "MESG_TYPE", "$timeout","$rootScope",
            function ($q, ybHttp, ybConfig, $window, $filter, EventBus, Upload, ybWidget, MESG_TYPE, $timeout, $rootScope) {
                //js浮点型数字运算addition:加法，subtraction：减法，multiply：乘法,division:除法
                function fnAccNumber(type, arg1, arg2) {
                    var r1, r2, m, t1, t2, result;
                    if (arg1.toString().split('.').length > 1) {
                        r1 = arg1.toString().split('.')[1].length
                    } else {
                        r1 = 0
                    }
                    if (arg2.toString().split('.').length > 1) {
                        r2 = arg2.toString().split('.')[1].length
                    } else {
                        r2 = 0;
                    }
                    t1 = Number(arg1.toString().replace('.', ''));
                    t2 = Number(arg2.toString().replace('.', ''));
                    switch (type) {
                        case 'addition':
                            result = (t1 * Math.pow(10, r2) + t2 * Math.pow(10, r1)) / Math.pow(10, r1 + r2);
                            break;
                        case 'subtraction':
                            result = (t1 * Math.pow(10, r2) - t2 * Math.pow(10, r1)) / Math.pow(10, r1 + r2);
                            break;
                        case 'multiply':
                            m = Math.pow(10, r1 + r2);
                            result = t1 * t2 / m;
                            break;
                        case 'division':
                            m = Math.pow(10, r2 - r1);
                            result = (t1 / t2) / m;
                            break;
                        default:
                            break;
                    }
                    return result;
                }

                function fnListGroup(srcPrintList, groupSize, cycleIndex = 1, dstPrintList = []) {
                    var pageItem = [];
                    var cycleStart = groupSize * (cycleIndex - 1);
                    for (var i = cycleStart; i < srcPrintList .length; i++) {
                        if (i < (groupSize * cycleIndex)) {
                            pageItem.push(srcPrintList [i]);
                            if (i === (srcPrintList .length - 1)) {
                                dstPrintList.push(pageItem);
                            }
                        } else {
                            dstPrintList.push(pageItem);
                            pageItem = [];
                            cycleIndex += 1;
                            fnListGroup(srcPrintList, groupSize, cycleIndex, dstPrintList);
                            break;
                        }
                    }
                    return dstPrintList;
                }

                var fnDebounce = function(fn, delay = 500, immediate = true) {
                    let timer = null

                    return function() {
                        const context = this
                        const args = arguments
                        clearTimeout(timer)

                        if(immediate) {
                            const runNow = !timer
                            // 设置定时器，指定时间后设置为null
                            timer = setTimeout(function() {
                                timer = null
                            }, delay)
                            // 如果timer已经为null（已到期），则执行函数
                            if(runNow) fn.apply(context, args)
                        } else {
                            // 如果没有设置立即执行，则设置定时器
                            timer = setTimeout(function() {
                                fn.apply(context, args)
                            }, delay)
                        }
                    }
                };

                var _rights;

                var ApplyRights = function () {
                    var service = "auth";
                    var reqUrl = "/scepter/getAuthCodes";
                    ybHttp.Get(service, reqUrl).then(function (resp) {
                        if (resp.code !== 0) {
                            return;
                        }
                        _rights = resp.value;
                        EventBus.Publish('AlreadyGetAuthCodes');

                        localStorage.setItem("AuthCodes", _rights);
                    });
                };

                function fnGetAuthCodes() {
                    _rights = localStorage.getItem("AuthCodes");
                    if (!!_rights) {
                        _rights = _rights.split(",");
                        for (var i = 0; i < _rights.length; i++) {
                            _rights[i] = parseInt(_rights[i]);
                        }
                        return;
                    }
                    ApplyRights();
                }

                function fnCheckPermission(ids) {
                    var ret = false;
                    if (!ids || ids.length == 0 || angular.isUndefined(_rights)) {
                        return true;
                    }
                    for (var i = 0; i < ids.length; ++i) {
                        ret = $filter('contains')(_rights, Number(ids[i]));
                        if (ret) {
                            return ret;
                        }
                    }
                    return ret;
                }

                function fnSetBtnPermission(cb) {
                    if (_rights) {
                        cb();
                    } else {
                        EventBus.Subscribe('AlreadyGetAuthCodes', cb);
                    }
                }

                function clearStorageExcludeLang() {
                    const hisLang = localStorage.getItem('lang');
                    localStorage.clear();
                    hisLang && localStorage.setItem('lang', hisLang);
                }

                var fnLogin = function (user) {
                    clearStorageExcludeLang();

                    var deferred = $q.defer();
                    var service = "auth";
                    var reqUrl = "/auth/login";
                    const userData = angular.copy(user);
                    userData.version = '20220805';
                    // userData.password = window.btoa(window.btoa(user.password));
                    var result = ybHttp.Post(service, reqUrl, userData);
                    result.then(function (data) {
                        if (data.code === 0) {
                            localStorage.setItem("ScAuthC", data.value.ScAuth);
                            deferred.resolve(data.value);
                            return;
                        }
                        deferred.reject(data.message);
                    }, function (data) {
                        deferred.reject(data.message);
                    });
                    return deferred.promise;
                };

                var fnLogOut = function (noNeedLogout, noNeed2loginPage) {
                    clearStorageExcludeLang();
                    
                    _rights = undefined;
                    if (!noNeedLogout) {
                        ybHttp.Post('auth', '/auth/logout');
                    }
                    if (!noNeed2loginPage) {
                        $window.location.href = ybConfig.getConfig().baseUrl.LoginSite;
                    }
                };

                function _getUserInfo() {
                    var userInfo = JSON.parse(localStorage.getItem("UserInfo"));
                    if (!!userInfo) {
                        $timeout(function () {
                            EventBus.Publish("getUserInfo", userInfo)
                        });
                        return $q.when(userInfo);
                    }
                    var service = "auth";
                    var reqUrl = "/profile/getLogin";
                    return ybHttp.Get(service, reqUrl).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        localStorage.setItem("UserInfo", JSON.stringify(resp.value));
                        EventBus.Publish("getUserInfo", resp.value);
                        return resp.value;
                    });
                }

                function _getSelfCompanyInfo() {
                const companyInfo = JSON.parse(localStorage.getItem("CompanyInfo"));
                    if (!!companyInfo) {
                        $timeout(function () {
                            EventBus.Publish("getSelfCompanyInfo", companyInfo)
                        });
                        return $q.when(companyInfo);
                    }
                    var service = "device";
                    var reqUrl = "/company/selfCompanyInfo";
                    return ybHttp.Get(service, reqUrl).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return null;
                        }

                        const companyTemp = resp.value
                        if (!companyTemp) {
                            ybWidget.ShowMessage('没有查询到企业信息', MESG_TYPE.Error);
                            return null;
                        }

                        localStorage.setItem("CompanyInfo", JSON.stringify(companyTemp));
                        EventBus.Publish("getSelfCompanyInfo", companyTemp);
                        return companyTemp;
                    });
                }

                function fnGetLodopObj() {
                    let lodopIns = null
                    lodopIns = getLodop(errHandle);
                    return lodopIns;
                }

                function errHandle(err) {
                    ybWidget.ShowMessage(err, MESG_TYPE.ERROR, {
                        isHtml: true
                    });
                }

                // item为需要判断的零件元素 currentQty为当前的填入的库存数量
                function fnSetStockStatusFlag(item, currentQty) {
                    if (angular.isUndefined(item) || !currentQty) {
                        return;
                    }
                    var msgArray = ['库存充足可用', '意向占用库存不足', '发货占用库存不足', '实际库存不足'];
                    var stockDiffArray = [];
                    // ['deliveryQty','enableNum','intentionNum','deliveryNum']
                    var intentionDiff = (+item.enableNum) - (+item.intentionNum);
                    var deliveryDiff = (+item.enableNum) - (+item.deliveryNum);
                    stockDiffArray.push(0);
                    stockDiffArray.push(intentionDiff);
                    stockDiffArray.push(deliveryDiff);
                    stockDiffArray.push(+item.enableNum);
                    // 当前数量 + （意向/发货）占用 > 实际库存，则库存标记颜色
                    for (var i = stockDiffArray.length - 1; i >= 1; i--) {
                        var stockDiff = stockDiffArray[i] - currentQty;
                        if (stockDiff < 0) {
                            item.qtyStockErr = true; // 库存状态异常
                            item.qtyErrMsg = msgArray[i];
                            item.qtyStockErrLevel = i; // 0表示正常，1表示意向占用不足，2表示发货占用不足，3表示实际库存不足
                            return;
                        }
                    }
                    item.qtyStockErr = false; // 表示实际库存值正常
                    item.qtyErrMsg = msgArray[0];
                    item.qtyStockErrLevel = 0;
                }

                let printIndex4barcodeListPrint;

                function initPrintTaskName(lodop, tempType) {
                    var initName = "";
                    switch (tempType) {
                        case 2:
                            initName = "挖机大标签";
                            break;
                        case 3:
                            initName = "挖机中标签";
                            break;
                        case 4:
                            initName = "挖机小标签";
                            break;
                        case 5:
                            initName = "进出口模板";
                            break;
                        default:
                            initName = "广汽仓储标签";
                            break;
                    }
                    lodop.PRINT_INIT(initName);
                    if (printIndex4barcodeListPrint != undefined) {
                        lodop.SET_PRINTER_INDEXA(printIndex4barcodeListPrint);
                    }
                }

                function fnInitPrinter(lodop, barcodePrinter, tempType) {
                    initPrintTaskName(lodop, tempType);
                    return new Promise(function (resolve, reject) {
                        const savedPrinters = JSON.parse(localStorage.getItem("yb.printerSettingList")||'[]');
                        const resPrinter = (barcodePrinter ? savedPrinters[1] : savedPrinters[0]) || { PrinterIdx: lodop.GET_PRINTER_COUNT() - 1 } // 设置最后一个打印机为默认打印机
                        lodop.SET_PRINTER_INDEXA(resPrinter.PrinterIdx);
                        printIndex4barcodeListPrint = barcodePrinter ? resPrinter.PrinterIdx : undefined; // 记录使用的打印机序号（条码打印ListPrint使用）
                        resolve(true);
                    });
                    /* return ybHttp.Get("device", "/printerConfig/view").then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return !$rootScope.isJCH;
                        }

                        if (!resp.value) {
                            // 用户之前未设置打印机：数据库里没有记录
                            if ($rootScope.isJCH) {
                                ybWidget.ShowMessage("您还未设置打印机，请先设置打印机！", MESG_TYPE.ERROR, { isHtml: false });
                            } else {
                                // 设置最后一个打印机为默认打印机
                                const defaultPrintIndex = lodop.GET_PRINTER_COUNT() - 1;
                                lodop.SET_PRINTER_INDEXA(defaultPrintIndex)
                                printIndex4barcodeListPrint = barcodePrinter ? defaultPrintIndex : undefined;
                            }
                            return !$rootScope.isJCH;
                        }

                        const savedPrinters = JSON.parse(resp.value.printerJson);
                        const resPrinter = barcodePrinter ? savedPrinters[1] : savedPrinters[0]
                        lodop.SET_PRINTER_INDEXA(resPrinter.PrinterIdx);
                        printIndex4barcodeListPrint = barcodePrinter ? resPrinter.PrinterIdx : undefined; // 记录使用的打印机序号（条码打印ListPrint使用）
                        return true;
                    }) */
                }

                // 集团模板
                function fnCreatePrintTpl(lodop, obj) {
                    lodop.ADD_PRINT_LINE("40.4mm", "2.09mm", "40.11mm", "97.39mm", 0, 1);
                    lodop.SET_PRINT_STYLEA(0, "ItemType", 1); // 设定打印项的基本属性--页眉页脚类型的打印
                    lodop.ADD_PRINT_LINE("40.19mm", "70.99mm", "13.2mm", "71.28mm", 0, 1);
                    var barCodeContent = obj.barcode;
                    if (barCodeContent.indexOf("http") === -1) {
                        barCodeContent = window.AppData.config.baseUrl.TracePage + barCodeContent;
                    }
                    lodop.ADD_PRINT_BARCODE("14.58mm", "71.99mm", "36mm", "36mm", "QRCode", barCodeContent);
                    lodop.SET_PRINT_STYLEA(0, "QRCodeVersion", 7);

                    lodop.SET_PRINT_STYLE("FontName", "微软雅黑");
                    
                    lodop.ADD_PRINT_TEXT("6.5mm", "40.01mm", "50.01mm", "5mm", obj.billNo);
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 12);
                    lodop.SET_PRINT_STYLEA(0, "Bold", 1);
                    lodop.ADD_PRINT_TEXT("16mm", "5mm", "12.01mm", "5mm", "编码");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.ADD_PRINT_TEXT("22.5mm", "5mm", "12.01mm", "10mm", "描述");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.ADD_PRINT_TEXT("16mm", "16mm", "53mm", "5mm", obj.materialsNo);
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.SET_PRINT_STYLEA(0, "Bold", 1);
                    lodop.ADD_PRINT_TEXT("22.5mm", "16mm", "53mm", "10mm", obj.materialsDes);
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.SET_PRINT_STYLEA(0, "Bold", 1);
                    lodop.ADD_PRINT_TEXT("34mm", "5mm", "12.01mm", "5mm", "储位");
                    lodop.ADD_PRINT_TEXT("34mm", "16mm", "53mm", "5mm", obj.locationDesc);
                    lodop.ADD_PRINT_TEXT("42.5mm", "5mm", "12.01mm", "5mm", "条码");
                    lodop.ADD_PRINT_TEXT("47.5mm", "5mm", "12.01mm", "5mm", "VIN");
                    lodop.ADD_PRINT_TEXT("42.5mm", "16mm", "40.01mm", "5mm", obj.barcode);
                    lodop.ADD_PRINT_TEXT("47.5mm", "16mm", "50.01mm", "5mm", obj.vinid);
                    lodop.ADD_PRINT_TEXT("42.5mm", "66.01mm", "30mm", "5mm", ((obj.barcodeFlag === 1) ? obj.currentQty + "/" : "") + obj.totalQty);
                    lodop.SET_PRINT_STYLEA(0, "Alignment", 3);
                    lodop.ADD_PRINT_TEXT("47.5mm", "61.01mm", "35mm", "5mm", ((obj.barcodeFlag === 1) ? "分" + obj.seq + "/" : "") + "总" + obj.childCount);
                    lodop.SET_PRINT_STYLEA(0, "Alignment", 3);
                    lodop.ADD_PRINT_TEXT("57mm", "71.01mm", "25mm", "5mm", $filter('YbDate')(+new Date()));
                    lodop.SET_PRINT_STYLEA(0, "Alignment", 3);
                    lodop.NEWPAGEA();
                }

                //挖机大模板
                function fnCreateExcavatorPrintTagFor100(lodop, obj) {
                    var barCodeContent = obj.barcode;
                    if (barCodeContent.indexOf("http") === -1) {
                        barCodeContent = window.AppData.config.baseUrl.TracePage + barCodeContent;
                    }

                    lodop.ADD_PRINT_BARCODE("21.96mm", "8.13mm", "26.46mm", "26.46mm", "QRCode", barCodeContent);

                    lodop.SET_PRINT_STYLE("FontName", "微软雅黑");

                    /** label */
                    lodop.ADD_PRINT_TEXT("14.55mm", "37.15mm", "22.49mm", "7.94mm", "零件中文名："); // 零件中文名
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);

                    lodop.ADD_PRINT_TEXT("24.61mm", "37.15mm", "22.49mm", "7.94mm", "Name："); // 零件英文描述
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);

                    lodop.ADD_PRINT_TEXT("34.67mm", "37.15mm", "28mm", "7.94mm", "零件编号(No.)："); // 零件编号
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);
                    lodop.ADD_PRINT_TEXT("44.46mm", "37.15mm", "22.49mm", "7.94mm", "数量："); // 数量
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);
                    lodop.ADD_PRINT_TEXT("53.98mm", "37.15mm", "22.49mm", "7.94mm", "序列号："); // 序列号
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);




                    /** value */
                    lodop.ADD_PRINT_TEXT("14.55mm", "55.01mm", "50.27mm", "7.94mm", obj.materialsDes); // 零件中文名
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);

                    lodop.ADD_PRINT_TEXT("24.61mm", "55.01mm", "50.27mm", "7.94mm", obj.materialsDesEn); // 零件英文描述
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);

                    lodop.ADD_PRINT_TEXT("34.67mm", "62mm", "50.27mm", "7.94mm", obj.materialsNo); // 零件编号
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);
                    if (obj.barcodeFlag === 0) {
                        lodop.ADD_PRINT_TEXT("44.46mm", "55.01mm", "50.27mm", "7.94mm", obj.currentQty + "[总]"); // 数量
                    } else if (obj.barcodeFlag === 1) {
                        lodop.ADD_PRINT_TEXT("44.46mm", "55.01mm", "50.27mm", "7.94mm", obj.currentQty + "[分]"); // 数量
                    } else {
                        lodop.ADD_PRINT_TEXT("44.46mm", "55.01mm", "50.27mm", "7.94mm", obj.currentQty); // 数量
                    }
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);
                    lodop.ADD_PRINT_TEXT("53.98mm", "52.36mm", "50.27mm", "7.94mm", obj.billNo); // 序列号
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 10);

                    lodop.NEWPAGEA();
                }

                // 挖机中模板
                function fnCreateExcavatorPrintTagFor60(lodop, obj, qrCodeBase64data, needExtraMsg) {
                    lodop.SET_PRINT_STYLE("FontName", "微软雅黑");

                    lodop.ADD_PRINT_TEXT("14.39mm", "19.39mm", "21.17mm", "4.76mm", "零件中文名：");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);

                    lodop.ADD_PRINT_TEXT("20.29mm", "19.39mm", "21.17mm", "4.76mm", "Name：");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);

                    lodop.ADD_PRINT_TEXT("26.19mm", "19.39mm", "21.17mm", "4.76mm", "零件编号(No.)：");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);
                    lodop.ADD_PRINT_TEXT("30.9mm", "19.39mm", "21.17mm", "4.76mm", "数量：");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);
                    lodop.ADD_PRINT_TEXT("35.9mm", "19.39mm", "21.17mm", "4.76mm", "序列号：");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);




                    lodop.ADD_PRINT_TEXT("14.39mm", "31.35mm", "30.11mm", "4.76mm", obj.materialsDes); // 零件中文名内容
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);

                    lodop.ADD_PRINT_TEXT("20.29mm", "31.35mm", "30.11mm", "4.76mm", obj.materialsDesEn); // 零件英文描述
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);

                    if (obj.barcodeFlag === 0) {
                        lodop.ADD_PRINT_TEXT("26.19mm", "37mm", "30.11mm", "4.76mm", obj.materialsNo + "[总]"); // 零件编号
                    } else if (obj.barcodeFlag === 1) {
                        lodop.ADD_PRINT_TEXT("26.19mm", "37mm", "30.11mm", "4.76mm", obj.materialsNo + "[分]"); // 零件编号
                    } else {
                        lodop.ADD_PRINT_TEXT("26.19mm", "37mm", "30.11mm", "4.76mm", obj.materialsNo); // 零件编号
                    }
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);

                    lodop.ADD_PRINT_TEXT("30.9mm", "31.35mm", "29.1mm", "4.76mm", obj.currentQty); // 数量
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);

                    lodop.ADD_PRINT_TEXT("35.9mm", "27.99mm", "31.99mm", "4.76mm", obj.billNo); // 序列编号
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 7);

                    if (needExtraMsg) {
                        lodop.ADD_PRINT_TEXT("14.39mm", "1.35mm", "18mm", "4.76mm", "扫码验真伪");
                        lodop.SET_PRINT_STYLEA(0, "FontSize", 7);
                        lodop.SET_PRINT_STYLEA(0, "Alignment", 2);
                    }

                    lodop.ADD_PRINT_IMAGE("19mm", "1.35mm", "17.01mm", "17.01mm", qrCodeBase64data);
                    lodop.SET_PRINT_STYLEA(0, "Stretch", 2);
                    lodop.NEWPAGEA();
                }

                // 挖机小模板--具体实现
                function fnCreateExcavatorPrintTagFor30(lodop, odd, even) {
                    var oddBarCode = odd.barcode;
                    var evenBarCode = even ? even.barcode : null;
                    if (oddBarCode.indexOf("http") === -1) {
                        oddBarCode = window.AppData.config.baseUrl.TracePage + oddBarCode;
                    }
                    lodop.ADD_PRINT_BARCODE("11.14mm", "7.28mm", "25.14mm", "25.14mm", "QRCode", oddBarCode);

                    lodop.SET_PRINT_STYLE("FontName", "微软雅黑");

                    lodop.ADD_PRINT_TEXT("32mm", "7.28mm", "21.17mm", "4.76mm", "编码：");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 6);

                    lodop.ADD_PRINT_TEXT("35mm", "7.28mm", "21.17mm", "4.76mm", "描述：");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 6);

                    lodop.ADD_PRINT_TEXT("32mm", "13mm", "25mm", "4.76mm", odd.materialsNo + (evenBarCode ? "[总]" : "[分]")); // 零件编号
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 6);

                    lodop.ADD_PRINT_TEXT("35mm", "13mm", "25mm", "4.76mm", odd.materialsDes); // 零件编号内容
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 6);


                    if (!!evenBarCode) {
                        evenBarCode = window.AppData.config.baseUrl.TracePage + evenBarCode;
                        lodop.ADD_PRINT_BARCODE("11.14mm", "39.69mm", "25.14mm", "25.14mm", "QRCode", evenBarCode);

                        lodop.ADD_PRINT_TEXT("32mm", "39.69mm", "21.17mm", "4.76mm", "编码：");
                        lodop.SET_PRINT_STYLEA(0, "FontSize", 6);

                        lodop.ADD_PRINT_TEXT("35mm", "39.69mm", "21.17mm", "4.76mm", "描述：");
                        lodop.SET_PRINT_STYLEA(0, "FontSize", 6);

                        lodop.ADD_PRINT_TEXT("32mm", "45.41mm", "25mm", "4.76mm", even.materialsNo + "[分]"); // 零件编号
                        lodop.SET_PRINT_STYLEA(0, "FontSize", 6);

                        lodop.ADD_PRINT_TEXT("35mm", "45.41mm", "25mm", "4.76mm", even.materialsDes); // 零件编号内容
                        lodop.SET_PRINT_STYLEA(0, "FontSize", 6);
                    }

                    lodop.NEWPAGEA();
                }

                // 挖机小模板
                function fnCreateExcavatorPrintTagGroupFor30(lodop, printGroup) {
                    fnCreateExcavatorPrintTagFor30(lodop, printGroup[0], printGroup.length == 2 ? printGroup[1] : null)
                }

                /* wangcan:条码管理-进出口模板 */
                function fnJCKPrintTpl(lodop, obj) {
                    var barCodeContent = obj.barcode;
                    if (barCodeContent.indexOf("http") === -1) {
                        barCodeContent = window.AppData.config.baseUrl.TracePage + barCodeContent + '&printType=5';
                    }      
                    // lodop.ADD_PRINT_BARCODE("21.96mm", "8.13mm", "26.46mm", "26.46mm", "QRCode", barCodeContent);              
                    lodop.SET_PRINT_STYLE("FontSize",9);
                    lodop.SET_PRINT_STYLE( "FontName", "黑体")
                    lodop.SET_PRINT_PAGESIZE(1, "100mm","65mm","")


                    lodop.ADD_PRINT_TEXT("13mm", "3mm", "25mm", "6mm", "PART NUMBER:");
                    lodop.ADD_PRINT_TEXT("18mm", "3mm", "25mm", "6mm", "NAME:");

                    if(!!obj.originalMaterialsNo){
                        lodop.ADD_PRINT_TEXT("13mm", "29mm", "55mm", "6mm", obj.materialsNo + "（" +  obj.originalMaterialsNo + "）");
                    }else{
                        lodop.ADD_PRINT_TEXT("13mm", "29mm", "55mm", "6mm", obj.materialsNo);
                    }
                    lodop.SET_PRINT_STYLEA(0,"FontSize",12);
                    lodop.SET_PRINT_STYLEA(0,"Bold",1);

                    lodop.ADD_PRINT_TEXT("18mm", "29mm", "70mm", "6mm", obj.materialsDes);
                    lodop.ADD_PRINT_TEXT("25mm", "29mm", "70mm", "6mm", obj.materialsDesEn);

                    lodop.ADD_PRINT_TEXT("32mm", "3mm", "25mm", "5mm", "BATCH NO.:");
                    lodop.ADD_PRINT_TEXT("37mm", "3mm", "40mm", "5mm", "BARCODE NUMBER:");
                    lodop.ADD_PRINT_TEXT("32mm", "29mm", "55mm", "5mm", obj.batchNo);
                    lodop.ADD_PRINT_TEXT("37mm", "29mm", "55mm", "5mm", obj.barcode);

                    lodop.ADD_PRINT_TEXT("42mm", "3mm", "25mm", "5mm", "QUANTITY:");
                    lodop.ADD_PRINT_TEXT("47mm", "3mm", "25mm", "5mm", "DESTINATION:");
                    lodop.ADD_PRINT_TEXT("52mm", "3mm", "25mm", "5mm", "MACHINE MODEL:");
                    lodop.ADD_PRINT_TEXT("42mm", "29mm", "55mm", "5mm", obj.currentQty);
                    lodop.ADD_PRINT_TEXT("47mm", "29mm", "55mm", "5mm", obj.destinnation);
                    lodop.ADD_PRINT_TEXT("52mm", "29mm", "40mm", "5mm", obj.machineModel);

                    lodop.ADD_PRINT_BARCODE("32mm", "70mm", "25mm", "25mm", "QRCode", barCodeContent);
                    lodop.SET_PRINT_STYLEA(0, "QRCodeVersion", 7);

                    lodop.NEWPAGEA();//多条打印预览分页，加载新的打印页面
                }

                /* 发运交接单二维码打印模板 */
                function barcodePrintTpl(lodop, obj) {
                    lodop.SET_PRINT_STYLE("FontName", "微软雅黑");

                    lodop.SET_PRINT_STYLE("FontSize",10);
                    lodop.SET_PRINT_PAGESIZE(1, "100mm","65mm","")

                    var barCodeContent = window.AppData.config.baseUrl.BarcodeBoxPage + obj.boxupId;
                    lodop.ADD_PRINT_BARCODE("10mm", "20mm", "25mm", "25mm", "QRCode", barCodeContent);
                    lodop.SET_PRINT_STYLEA(0, "QRCodeVersion", 7);
                    lodop.ADD_PRINT_TEXT("47mm", "10mm", "25mm", "6mm", "单号:");
                    lodop.ADD_PRINT_TEXT("53mm", "10mm", "40mm", "6mm", "箱号:");
                    lodop.ADD_PRINT_TEXT("47mm", "19mm", "55mm", "6mm", obj.billNo);
                    lodop.ADD_PRINT_TEXT("53mm", "19mm", "55mm", "6mm", obj.boxupNo);

                    lodop.NEWPAGEA();//多条打印预览分页，加载新的打印页面
                }

                // 巴西二维码模板
                function fnBXPrintTpl(lodop, obj) {
                    lodop.SET_PRINT_STYLE("FontName", "微软雅黑");

                    lodop.SET_PRINT_STYLE("FontSize",9);
                    lodop.SET_PRINT_PAGESIZE(1, "100mm","65mm","")


                    lodop.ADD_PRINT_TEXT("13mm", "3mm", "25mm", "6mm", "Código:"); // 零件编号
                    lodop.ADD_PRINT_TEXT("18mm", "3mm", "25mm", "6mm", "Desc ch:"); // 中文描述
                    lodop.ADD_PRINT_TEXT("25mm", "3mm", "25mm", "6mm", "Des port:");// 葡语描述

                    lodop.ADD_PRINT_TEXT("13mm", "29mm", "55mm", "6mm", obj.materialsNo);
                    lodop.SET_PRINT_STYLEA(0,"FontSize",12); // 零件编号字体增大
                    lodop.SET_PRINT_STYLEA(0,"Bold",1); // 零件编号字号加粗

                    lodop.ADD_PRINT_TEXT("18mm", "29mm", "70mm", "6mm", obj.materialsDes);
                    lodop.ADD_PRINT_TEXT("25mm", "29mm", "70mm", "6mm", obj.portugueseShort);


                    lodop.ADD_PRINT_TEXT("32mm", "3mm", "25mm", "5mm", "Qtd:"); // 数量
                    lodop.ADD_PRINT_TEXT("37mm", "3mm", "40mm", "5mm", "Cod barra:"); // 条码
                    lodop.ADD_PRINT_TEXT("32mm", "29mm", "55mm", "5mm", obj.currentQty);
                    lodop.ADD_PRINT_TEXT("37mm", "29mm", "55mm", "5mm", obj.barcode);


                    lodop.ADD_PRINT_TEXT("42mm", "3mm", "40mm", "5mm", "Mod maq:"); // 机型
                    lodop.ADD_PRINT_TEXT("42mm", "29mm", "40mm", "5mm", obj.machineModelBx);


                    lodop.ADD_PRINT_BARCODE("32mm", "70mm", "25mm", "25mm", "QRCode", obj.barcode);
                    lodop.SET_PRINT_STYLEA(0, "QRCodeVersion", 7);

                    lodop.ADD_PRINT_TEXT("57mm", "70mm", "25mm", "5mm", $filter('YbDate')(+new Date()));
                    lodop.SET_PRINT_STYLEA(0, "Alignment", 2);

                    lodop.NEWPAGEA();//多条打印预览分页，加载新的打印页面
                }

                // 铲运矿机模板
                function fnCHYPrintTpl(lodop, obj) {
                    lodop.ADD_PRINT_LINE("40.4mm", "2.09mm", "40.11mm", "97.39mm", 0, 1);
                    lodop.SET_PRINT_STYLEA(0, "ItemType", 1);
                    lodop.ADD_PRINT_LINE("40.19mm", "70.99mm", "13.2mm", "71.28mm", 0, 1);
                    var barCodeContent = obj.barcode;
                    if (barCodeContent.indexOf("http") === -1) {
                        barCodeContent = window.AppData.config.baseUrl.TracePage + barCodeContent;
                    }
                    lodop.ADD_PRINT_BARCODE("14.58mm", "71.99mm", "36mm", "36mm", "QRCode", barCodeContent);
                    lodop.SET_PRINT_STYLEA(0, "QRCodeVersion", 7);

                    lodop.SET_PRINT_STYLE("FontName", "微软雅黑");

                    lodop.ADD_PRINT_TEXT("16mm", "5mm", "12.01mm", "5mm", "编码");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.ADD_PRINT_TEXT("22.5mm", "5mm", "12.01mm", "10mm", "描述");
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.ADD_PRINT_TEXT("16mm", "16mm", "53mm", "5mm", obj.materialsNo);
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.SET_PRINT_STYLEA(0, "Bold", 1);
                    lodop.ADD_PRINT_TEXT("22.5mm", "16mm", "53mm", "10mm", obj.materialsDes);
                    lodop.SET_PRINT_STYLEA(0, "FontSize", 11);
                    lodop.SET_PRINT_STYLEA(0, "Bold", 1);
                    lodop.ADD_PRINT_TEXT("34mm", "5mm", "12.01mm", "5mm", "储位");
                    lodop.ADD_PRINT_TEXT("34mm", "16mm", "53mm", "5mm", obj.locationDesc);
                    lodop.ADD_PRINT_TEXT("42.5mm", "5mm", "12.01mm", "5mm", "条码");
                    lodop.ADD_PRINT_TEXT("47.5mm", "5mm", "12.01mm", "5mm", "VIN");
                    lodop.ADD_PRINT_TEXT("42.5mm", "16mm", "40.01mm", "5mm", obj.barcode);
                    lodop.ADD_PRINT_TEXT("47.5mm", "16mm", "50.01mm", "5mm", obj.vinid);
                    lodop.ADD_PRINT_TEXT("42.5mm", "66.01mm", "30mm", "5mm", ((obj.barcodeFlag === 1) ? obj.currentQty + "/" : "") + obj.totalQty);
                    lodop.SET_PRINT_STYLEA(0, "Alignment", 3);
                    lodop.ADD_PRINT_TEXT("47.5mm", "61.01mm", "35mm", "5mm", ((obj.barcodeFlag === 1) ? "分" + obj.seq + "/" : "") + "总" + obj.childCount);
                    lodop.SET_PRINT_STYLEA(0, "Alignment", 3);
                    lodop.ADD_PRINT_TEXT("52mm", "5mm", "50.01mm", "5mm", obj.billNo);
                    lodop.ADD_PRINT_TEXT("52mm", "71.01mm", "25mm", "5mm", $filter('YbDate')(+new Date()));
                    lodop.SET_PRINT_STYLEA(0, "Alignment", 3);
                    lodop.NEWPAGEA();
                }

                /* 处理打印中模板
                   @param {Boolean} needExtraMsg：挖机中模板false，中模板为true----(增加了一行文字描述:"扫码验真伪")
                */
                function handlePrintTag4zhong(lodop, printSourceData, needExtraMsg) {
                    return createQRCode(printSourceData).then(function (qrCodes) {
                        angular.forEach(printSourceData, function (item, index) {
                            fnCreateExcavatorPrintTagFor60(lodop, item, qrCodes[index], needExtraMsg);
                        });
                        return true;
                    });
                }

                function fnCreatPrintTplByPrintType(lodop, srcPrintList, printType) {
                    var createTplFn = null;
                    var dstPrintList = srcPrintList;
                    switch (printType) {
                        case 0: // 集团模板
                            createTplFn = fnCreatePrintTpl;
                            break;
                        case 2: //挖机大模板
                            createTplFn = fnCreateExcavatorPrintTagFor100;
                            break;
                        case 3: // 挖机中模板
                            return handlePrintTag4zhong(lodop, dstPrintList, false);
                        case 4: // 挖机小模板
                            createTplFn = fnCreateExcavatorPrintTagGroupFor30;
                            dstPrintList = fnListGroup(srcPrintList, 2); // 两个一组
                            break;
                        case 5: // 进出口模板
                            createTplFn = fnJCKPrintTpl;
                            break;
                        case 6: // 发运交接单二维码打印模板
                            createTplFn = barcodePrintTpl;
                            break;
                        case 7: // 巴西模板
                            createTplFn = fnBXPrintTpl;
                            break;
                        case 8: // 铲运矿机模板
                            createTplFn = fnCHYPrintTpl;
                            break;
                        case 9: // 中模板
                            return handlePrintTag4zhong(lodop, dstPrintList, true);
                        default:
                            return null;
                    }
                    angular.forEach(dstPrintList, function (item) {
                        createTplFn(lodop, item);
                    });
                    return $q.when(true);
                }

                function createQRCode(printList) {
                    var urlContentes = [];
                    angular.forEach(printList, function (item) {
                        var barCodeContent = item.barcode;
                        if (barCodeContent.indexOf("http") === -1) {
                            barCodeContent = window.AppData.config.baseUrl.TracePage + barCodeContent;
                        }
                        urlContentes.push(barCodeContent);
                    });
                    return getBase64QRCodeByUrlList(urlContentes);
                }

                function getBase64QRCodeByUrlList(urlList) {
                    var param = {
                        urles: urlList,
                        width: 200,
                        height: 200
                    };
                    return ybHttp.Post("device", "/barcode/qrCode", param).then(function (data) {
                        if (data.code !== 0) {
                            return [];
                        }
                        return data.value;
                    });
                }

                function fnPromiseForLoop() {
                    var nextPromise = null;
                    var defer = $q.defer();

                    function lodopItemFn(fnCB) {
                        if (!nextPromise) {
                            nextPromise = defer.promise;
                            fnCB().then(function () {
                                defer.resolve();
                            }, function () {
                                defer.reject();
                            })
                        } else {
                            nextPromise = nextPromise.then(function () {
                                return fnCB();
                            });
                        }
                        return nextPromise;
                    }
                    return lodopItemFn;
                }

                function checkMaterialHasGsInfo(arr) {
                    return new Promise(function (resolve, reject) {
                        resolve({});
                    });
                    /* return ybHttp.Post("device", "/materials/itemGsInfo", arr).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return {};
                        }
                        return resp.value || {}
                    }, function() {
                        return {};
                    }) */
                }

                function handleMaterialsNoAddTriangle(arr, materialsNoMap) {
                    if (Object.keys(materialsNoMap).length == 0) return
                    arr.forEach(a => {
                        if (materialsNoMap[a.materialsNo]) {
                            a.materialsNo = `▲ ${a.materialsNo}`
                        }
                    })
                }

                async function fnListPrint(printList, printer, printType, isPreview) {
                    if (printType == 1) { // 铲运专有模板
                        if (isPreview) {
                            printer.ADD_PRINT_HTM(0, 0, '100mm', '65.1mm', document.getElementById('printXgcy').innerHTML);
                            printer.PREVIEW();
                        } else {
                            for (var k = 0; k < printList.length; k++) {
                                printer.ADD_PRINT_HTM(0, 0, '100mm', '65.1mm', document.getElementById('cyTpl' + k).innerHTML);
                                printer.PRINT();
                            }
                        }
                        return
                    }

                    let printListTmp
                    if (isPreview) {
                        printListTmp = printList.map(pl => pl.materialsNo);
                    } else {
                        printListTmp = printList.reduce((total, pre) => total.concat(pre.map(p => p.materialsNo)), []);
                    }
                    const materialsNoRes = await checkMaterialHasGsInfo(Array.from(new Set(printListTmp)))

                    if (!(printType == 3 || printType == 9)) { // 非中条码模板，采用clodop生成的条码
                        function handlePreviewOrPrint1(pDatas) {
                            handleMaterialsNoAddTriangle(pDatas, materialsNoRes);
    
                            initPrintTaskName(printer, printType);
                            fnCreatPrintTplByPrintType(printer, pDatas, printType);
                        }

                        if (isPreview) {
                            handlePreviewOrPrint1(printList);
                            printer.PREVIEW();
                        } else {
                            for (var j = 0; j < printList.length; j++) {
                                handlePreviewOrPrint1(printList[j]);
                                printer.PRINT();
                            }
                        }
                        return;
                    }

                    // 中条码模板，采用后端服务生成条码
                    function handlePreviewOrPrint2(pDatas) {
                        handleMaterialsNoAddTriangle(pDatas, materialsNoRes);

                        initPrintTaskName(printer, printType);
                        return fnCreatPrintTplByPrintType(printer, pDatas, printType);
                    }

                    if (isPreview) {
                        handlePreviewOrPrint2(printList).then(function () {
                            printer.PREVIEW();
                        });
                    } else {
                        var promiseItem = fnPromiseForLoop();
                        for (var i = 0; i < printList.length; i++) {
                            promiseItem((function (i) {
                                return function () {
                                    return handlePreviewOrPrint2(printList[i]).then(function () {
                                        printer.PRINT();
                                    });
                                }
                            })(i));
                        }
                    }
                }

                function fnGetPwdLevel(value) {
                    var level = 0;
                    if (/^\S{6,20}$/.test(value)) { // 无空白字符（空白字符包括空格、换行、tab缩进等所有的空白），6到20位；
                        // 判断字符串中有没有数字
                        if (/\d/.test(value)) {
                            level++;
                        }
                        // 判断字符串中有没有小写字母
                        if (/[a-z]/.test(value)) {
                            level++;
                        }
                        // 判断字符串中有没有大写字母
                        if (/[A-Z]/.test(value)) {
                            level++;
                        }
                        // 判断字符串中有没有特殊字符
                        if (/\W/.test(value)) { // 特殊字符：数字、字母、下划线以外的其他字符
                            level++;
                        }
                    }
                    return level;
                }

                // 处理换行符、中文逗号，将其转换为指定符号(默认为英文逗号)
                function fnMultiInput(value, reg = '(\n|\uff0c)+', mark = ',') {
                    if (!value) {
                        return value;
                    }

                    var regE = null
                    if (reg instanceof RegExp) {
                        regE = reg
                    } else {
                        regE = new RegExp(reg, 'g')
                    }
                    var multiCodesT = value.replace(regE, mark);
                    if (multiCodesT && multiCodesT[0] === mark) {
                        multiCodesT = multiCodesT.substr(1);
                    }
                    if (multiCodesT && multiCodesT[multiCodesT.length - 1] === mark) {
                        multiCodesT = multiCodesT.slice(0, -1);
                    }
                    return multiCodesT;
                }

                function fnLocalCache(keyName, targetObj) {
                    const isOpen = $rootScope.isCHY;
                    if (isOpen) {
                        if (localStorage.getItem(keyName)) {
                            angular.extend(targetObj, JSON.parse(localStorage.getItem(keyName)));
                        }
                    }
                }

                function fnParseUrlParams(str) {
                    str = str || window.location.href
                    const params1T = str.split('?')[1] || ''
                    const params = params1T.split('&') || []
                    const obj = {};
                    for (let item of params) {
                        const paramsA = item.split('=');
                        const key = paramsA[0];
                        const value = decodeURIComponent(paramsA[1] || '');
                    
                        if (obj[key]) {
                            obj[key] = Array.isArray(obj[key]) ? obj[key] : [obj[key]];
                            obj[key].push(value);
                        } else {
                            obj[key] = value;
                        }
                    }
                    return obj;
                }
    
                function fnStringifyUrlParams(map) {
                    map = map || {}
                    let str = '?'
                    for (const key in map) {
                        if (Array.isArray(map[key])) {
                            for (const item of map[key]) {
                                str += `${key}=${item}&`
                            }
                        } else {
                            str += `${key}=${map[key]}&`
                        }
                    }
                    return str.substr(0, str.length -1)
                }

                // 去除对象中的（空字符串、null、undefined）
                function fnRemoveEmptyValues(obj) {
                    if (!obj) {
                        return obj;
                    }
                    return Object.keys(obj).reduce((acc, key) => {
                        const isEmptyObj = Object.prototype.toString.call(obj[key]) === '[object Object]' && Object.keys(obj[key]).length === 0;
                        const isEmptyArr = Array.isArray(obj[key]) && obj[key].length == 0;
                        if (obj[key] !== '' && obj[key] !== null && obj[key] !== undefined) {
                            acc[key] = obj[key];
                        }
                        return acc;
                    }, {});
                }

                /* 获取校验库存的orgId列表 start */
                async function _getPageCheckStock() {
                  $rootScope.checkStockQtyOrgIdData = {};
                  try {
                    let resp = await _getCheckStockQtySetting();
                    if (resp.code !== 0 || resp.value.total < 1) {
                      return;
                    }

                    let pId = resp.value.list[0]?.id;
                    let settingsResp = await _getCheckStockQtyOrgId(pId)
                    if (settingsResp.code !== 0 || settingsResp.value.total < 1) {
                      return;
                    }
                    let checkOrgIdData = {};
                    for (const item of settingsResp.value.list) {
                      if (item.groupName != 'ON') {
                        continue;
                      }
                      if (!checkOrgIdData[item.name]) {
                        checkOrgIdData[item.name] = [];
                      }
                      let orgId = item.code.split('.')[0];
                      checkOrgIdData[item.name].push(orgId)
                    }
                    $rootScope.checkStockQtyOrgIdData = checkOrgIdData;
                  } catch (error) {
                    return;
                  }
                }
                function _getCheckStockQtySetting() {
                  var service = "device";
                  var reqUrl = "/dataDictionary/listAll";
                  var param = {
                    pageSize: 1,
                    pageNum: 1,
                    filters: {
                      code: 'CHECK_STOCK_QTY',
                    },
                  };
                  return ybHttp.Post(service, reqUrl, param);
                }
                function _getCheckStockQtyOrgId(pId) {
                  var service = "device";
                  var reqUrl = "/dataDictionary/list";
                  var param = {
                    pageSize: 500,
                    pageNum: 1,
                    filters: {
                      pId,
                    },
                  };
                  return ybHttp.Post(service, reqUrl, param)
                }
                /**
                 * 判断是否校验库存
                 * @param {String} pageName 页面名称
                 * @param {*} curOrgId 当前登录orgId
                 * @returns 是否需要校验库存
                 */
                function _needCheckStockQty(pageName, curOrgId) {
                  let pageData = $rootScope.checkStockQtyOrgIdData[pageName] || [];
                  if (pageData.length <= 0) {
                    return false
                  }
                  return pageData.includes(curOrgId)
                }
                /* 获取校验库存的orgId列表 end */

                function handleImgUploadInfo(sourceImgs, imgLabel = '图片', isRequired) {
                    let imgUploadOk = false;
                    let imgUrls = [];
                    if (sourceImgs && sourceImgs.length > 0) {
                      if (!sourceImgs.every(function (item) { return item.hasUpload })) {
                        ybWidget.ShowMessage(`有${imgLabel}未上传，请先上传图片再点击保存按钮!`, MESG_TYPE.Info);
                      } else {
                        imgUploadOk = true;
                        imgUrls = sourceImgs.map(function (item) { return item.imgUrl });
                      }
                    } else {
                      if (isRequired) {
                        ybWidget.ShowMessage(`没有${imgLabel}!`, MESG_TYPE.Info);
                      } else {
                        imgUploadOk = true;
                      }
                    }
                    return { imgUploadOk, imgUrls }
                }

                function getYbUpLoadObjConstructor(sourceData, sourceType, mnDir) {
                    sourceData = sourceData || []
                    sourceType = sourceType || 'ftp'
                    const imgRootObj = {
                      'ftp': ybConfig.getConfig().baseUrl.BjxlshFtp,
                      'oss': ybConfig.getConfig().baseUrl.ImgOssUrl,
                      'minio': ybConfig.getConfig().baseUrl.ImgMinioUrl + mnDir,
                    }
                    return sourceData.filter(Boolean).map(item => {
                      return {
                        imgUrl: item, // （和接口交互时使用的字段）
                        imgUrlShow: imgRootObj[sourceType] + item, // （页面展示时需要的字段）
                        hasUpload: true // 该张图片已经上传过（页面展示已上传图标时需要的字段）
                      }
                    })
                }

                function fnBarcodeInbound(sourceData, businessOrderKey, amountKey, inboundStatusKey) {
                    var service = "device";
                    var reqUrl = "/warehouseInboundRecord/add";
                    var param = {
                        recordList: []
                    };
                    var errorCount = 0;
                    angular.forEach(sourceData, function (item) {
                        var listRow = {};
                        listRow.barCode = item.barCode;
                        listRow.businessOrder = item[businessOrderKey];
                        listRow.amount = item[amountKey]; // 实际入库数量取计划入库数量(即入库一次性入完)
                        listRow.locationCode = item.locationCode;
                        listRow.crucialDevice = item.crucialDevice;
                        listRow.frozen = 0;
                        listRow.changeLocationRelation = false;

                        if ([0, 1].includes(item[inboundStatusKey]) && !item.locationCode) {
                            item.locationErr = true;
                            errorCount++;
                        }
                        param.recordList.push(listRow);
                    });
                    if (errorCount > 0) {
                        return Promise.reject('入库校验不通过，请检查！');
                    }
                    return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return Promise.reject(resp);
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        return Promise.resolve();
                    });
                }

                return {
                    AccNumber: fnAccNumber,
                    ListGroup: fnListGroup,
                    Debounce: fnDebounce,

                    Login: fnLogin,
                    Logout: fnLogOut,
                    CheckPermission: fnCheckPermission,
                    GetUserInfo: _getUserInfo,
                    GetSelfCompanyInfo: _getSelfCompanyInfo,
                    GetAuthCodes: fnGetAuthCodes,
                    SetStockStatusFlag: fnSetStockStatusFlag,
                    
                    GetLodop: fnGetLodopObj,
                    InitPrinter: fnInitPrinter,
                    CreatPrintTplByPrintType: fnCreatPrintTplByPrintType,
                    ListPrint: fnListPrint,
                    
                    GetPwdLevel: fnGetPwdLevel,
                    MultiInput: fnMultiInput,
                    LocalCache: fnLocalCache,
                    ParseUrlParams: fnParseUrlParams,
                    StringifyUrlParams: fnStringifyUrlParams,
                    RemoveEmptyValues: fnRemoveEmptyValues,

                    GetPageCheckStock: _getPageCheckStock,
                    NeedCheckStockQty: _needCheckStockQty,

                    HandleImgUploadInfo: handleImgUploadInfo,
                    GetYbUpLoadObjConstructor: getYbUpLoadObjConstructor,
                    ClearStorageExcludeLang: clearStorageExcludeLang,

                    SetBtnPermission: fnSetBtnPermission,

                    BarcodeInbound: fnBarcodeInbound
                }
            }
        ])
        ;
})
(window, window.angular);
